
/**
 * 电影信息页面
 */
let vf = new Vue({
    el: '#film-info',
    data: {
        user: JSON.parse(sessionStorage.getItem("user")),
        shows: [],
        currentShows: [],
        currentFilm: {},
        currentFilmComment: []
    },
    created() {

        // 获取本地存储的影片ID ，查询影片信息
        let formData = {
            filmId: localStorage.getItem("filmId")
        }
        $.get('http://localhost:8080/cinema/api/SelectFilmByIdServlet.do', formData, function (dto) {
            vf.currentFilm = dto.value;

            // 修改网页头 title 值
            $(document).attr("title", dto.value.filmName + "_电影票_特惠购票_低价订票_笑傲江湖影院");
        });


        // 根据影片ID 查询出所有的放映计划
        $.get('http://localhost:8080/cinema/api/SelectShowsByFilmIdServlet.do', formData, function (dto) {
            vf.shows = dto.value;
            vf.currentShows = vf.shows[0];

        });

        // 根据影片ID 查询出当前影片的所有评论
        $.get('http://localhost:8080/cinema/api/SelectCommentsByFilmIdServlet.do', formData, function (dto) {

            vf.currentFilmComment = dto.value;
        });



    },
    methods: {
        change: function () {
            if ($("#want-one").hasClass("layui-icon-heart")) {
                $("#want-one").removeClass("layui-icon-heart");
                $("#want-one").addClass("layui-icon-heart-fill font");
                $("#want-two").text("已想看");
                layer.msg("亲，么么哒");
            } else {
                $("#want-one").removeClass("layui-icon-heart-fill font");
                $("#want-one").addClass("layui-icon-heart");
                $("#want-two").text("想看");
            }
        },
        changeColor: function (i, event) {
            // 获取当前点击对象
            let a = event.currentTarget;

            //先把其他行的样式还原
            $(a).siblings().removeClass("btn-hover");
            //改变当前行的样式
            $(a).addClass("btn-hover");

            // 改变当前放映计划
            this.currentShows = this.shows[i];
        },
        chooseSeat: function (sid) {
            localStorage.setItem("showId", sid);

            location.href = "home_seatChoose.html";
        },
        writeComment: function () {
            //弹出一个页面层（评论）  
            layer.open({
                type: 1,
                skin: 'layui-layer-lan',
                title: '我的短评',
                anim: 1,   // 动画
                resize: false,  // 是否允许拉伸改变宽高
                area: ['550px', '450px'], // 设置宽，高
                shadeClose: false, //点击遮罩关闭
                content: $("#comment-form"),
                btn: ['提交', '取消'],
                btn1: function (index) {
                    let val = $("#comment-val");
                    if (val.val() == "") {
                        val.focus();
                        layer.msg("提交失败，内容为空", { offset: 't', icon: 5, anim: 6 });
                        return;
                    }

                    let formData = {
                        userName: vf.user.userName,
                        image: vf.user.image,
                        userId: vf.user.userId,
                        commentVal: val.val(),
                        filmName: vf.currentFilm.filmName,
                        filmId: vf.currentFilm.filmId
                    }
                    $.post('http://localhost:8080/cinema/api/CommentAddServlet.do', formData, function (dto) {
                        if (dto.code == 200) {
                            let formData2 = {
                                filmId: localStorage.getItem("filmId")
                            }
                            // 根据影片ID 查询出当前影片的所有评论
                            $.get('http://localhost:8080/cinema/api/SelectCommentsByFilmIdServlet.do', formData2, function (dto2) {

                                vf.currentFilmComment = dto2.value;
                            });
                            val.val("");
                            // 关闭弹出层
                            layer.close(index);
                            layer.msg(dto.value, { icon: 1 });

                        } else {
                            val.focus();
                            layer.msg(dto.msg, { offset: 't', icon: 5, anim: 6 });
                        }
                    });

                },
                btn2: function () {
                    $("#comment-val").val('');
                }
            });

        }
    }
});















